from django.shortcuts import render,redirect
from django.http import JsonResponse
from app02 import models
def chart_list(request):

    return render(request,'charts_list.html')

def chart_bar(request):

    """构造柱状图数据"""
    data_list=[
        {
            'name': '销量',
            'data': [120, 200, 150, 80, 70, 110, 130],
            'type': 'bar',
        }
    ]
    data_dict=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    result={
        'stuat':True,
        'data':{
            'data_list':data_list,
            'data_dict':data_dict
        }
    }

    return JsonResponse(result)

def chart_pie(request):
    # 构造饼图数据
    dict=[
        {'value': 1048, 'name': 'IT类'},
        {'value':735, 'name': '运营'},
        {'value': 580, 'name': '黑马'},
    ]
    result={
        'stuat':True,
        'data':dict
    }

    return JsonResponse(result)

def chart_line(request):
    # 构造折线图后台数据
    da=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    db=[150, 230, 224, 218, 135, 147, 260]

    result={
        'stuat':True,
         'data':{
             'da':da,
             'db':db
         }
    }

    return JsonResponse(result)